﻿Option Explicit On
Option Strict On

Imports NUnit.Framework
Imports CupsApp.Service
Imports CupsApp.Data
Imports System.Web.Ria
Imports System.Web.DomainServices
Imports System.Linq

<TestFixture()> _
Public Class CupsDomainServiceIntegrationTests

    Private _clientService As IClientDomainService
    Private _clientRepo As IRepository(Of cups_Client)

    <TestFixtureSetUp()> _
    Public Sub Setup()
        Dim context As CupsDataContext = New CupsDataContext()
        _clientRepo = New LinqToSqlRepository(Of cups_Client)(context)
        _clientService = New CupsDomainService(_clientRepo, Nothing, Nothing, Nothing, Nothing)
    End Sub

    <TestFixtureTearDown()> _
    Public Sub TearDown()

    End Sub

    <Test()> _
    Public Sub TestInsertAndDeleteAndQueryNewClient()
        Dim client As cups_Client = New cups_Client
        client.FirstName = "FirstName"
        client.LastName = "LastName"

        Dim id As Integer = _clientService.NewClient(client)

        Assert.IsNotNull(id, "Inserted client ID {0}", id)
        Assert.AreNotEqual(0, id, "Client has not been assigned", client.ID)

        Assert.IsTrue(_clientService.DeleteClient(client.ID), "Deleting client ID {0}", client.ID)


        Assert.IsNull(_clientService.GetClient(client.ID))


    End Sub


    <Test()> _
   Public Sub TestCanAccessRelatedEntity()
 

        Dim c As cups_Client = _clientService.GetClients().First()
        Dim s As cups_ClientStatus = c.cups_ClientStatus().First()

        Assert.AreEqual(1, s.ID)


    End Sub

 

End Class
